<template>
  <div class="early-warning">
    <img src="../../../assets/early-warning-bg.png" />
    <div class="title">
      <div class="title-left">
        <span>预警信息展示</span>
        <img src="../../../assets/show-title-bg.png" />
      </div>
    </div>
    <div class="early-warning-status">
      <div
        v-for="(item, index) in statusList"
        :key="index"
        @click="changeWarn(item)"
        class="early-warning-status-item"
      >
        <div class="status-text">
          <span>{{ item.num }}条</span>
          <span>{{ item.title }}</span>
        </div>
        <img :src="item.img" />
      </div>
    </div>
    <div class="early-warning-data-title">
      <img src="../../../assets/title-raidus.png" />
      <div class="early-warning-data-item">
        <span>序号</span>
        <span>隧道名称</span>
        <span>时间</span>
        <span>预报类型</span>
      </div>
    </div>
    <div class="early-warning-data">
      <div class="early-warning-data-view">
        <div class="early-warning-data-wrap">
          <div @click="towarn" v-for="item in warnList" :key="item.id" class="early-warning-data-item">
            <span>{{item.id}}</span>
            <span>{{item.tunnelName}}</span>
            <span>{{item.time}}</span>
            <span>{{item.warnMessage}}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import api from "../../../api";
export default {
  data() {
    return {
      tid: 5,
      warn: {
        // 二衬施工质量检测
        erquality: 0,
        // 监控量测预警
        monitor: 0,
        // 超前地质预报预警
        prediction: 0,
        // 初支施工质量检测
        quality: 0,
      },
      option: {},
      statusList: [
        {
          title: "监控预警",
          num: 1,
          img: "/images/early-warning-status1.png",
          typeWarn: 1,
        },
        {
          title: "预报预警",
          num: 3,
          img: "/images/early-warning-status2.png",
          typeWarn: 2,
        },
        {
          title: "初支预警",
          num: 6,
          img: "/images/early-warning-status3.png",
          typeWarn: 3,
        },
        {
          title: "二村预警",
          num: 2,
          img: "/images/early-warning-status4.png",
          typeWarn: 4,
        },
      ],
      warnList: [],
    };
  },
  mounted() {
    this.$bus.$on("early-warning", (row) => {
      this.warnList = [];
      this.tid = row;
      api
        .bigdatawarn({ tid: row })
        .then((res) => {
          if (res.data.code == 2001) {
            //监控预警
            this.statusList[0].num = Number(res.data.data.monitor);
            //预报预警
            this.statusList[1].num = Number(res.data.data.prediction);
            //初支预警
            this.statusList[2].num = Number(res.data.data.quality);
            //二村预警
            this.statusList[3].num = Number(res.data.data.erquality);
          }
        })
        .catch((err) => {
          console.log(err);
        });
  
        this.WarnfindByAll()
    });
  },
  methods: {
    WarnfindByAll(){
      api
        .WarnfindByAll({ page: 1,  tid: this.tid })
        .then((res) => {
          if (res.data.code == 2001) {
            console.log(res.data.data.records)
            this.warnList = res.data.data.records
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    changeWarn(item) {
      api
        .bigdatawarninfo({ tid: this.tid, type: item.typeWarn })
        .then((res) => {
          if (res.data.code == 2001) {
            this.warnList = res.data.data;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    towarn() {
      this.$router.push({ path: "/system/syswarnlog" });
    },
  },
};
</script>

<style lang="scss" scoped>
.early-warning {
  width: 100%;
  height: 37%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  padding-bottom: 1px;

  > img {
    width: 100%;
    height: 80%;
    position: absolute;
    left: 0;
    bottom: 0;
  }

  > .title {
    width: 100%;
    height: 43px;
    padding-right: 30px;
    position: relative;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;

    > span {
      color: #cecece;
      font-size: 18px;
    }

    > .title-left {
      width: 218px;
      height: 43px;
      display: flex;
      align-items: center;
      padding-left: 60px;
      position: relative;
      > img {
        width: 100%;
        height: 43px;
        position: absolute;
        left: 0;
        top: 0;
      }

      > span {
        position: relative;
        color: #fff;
        font-size: 18px;
      }
    }
  }

  .early-warning-status {
    width: 100%;
    height: 100px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;

    .early-warning-status-item {
      width: 86px;
      height: 86px;
      position: relative;

      > img {
        width: 100%;
        height: 100%;
        position: absolute;
        left: 0;
        top: 0;
      }

      .status-text {
        cursor: pointer;
        width: 100%;
        height: 100%;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        position: relative;
        z-index: 99;

        > span:nth-child(1) {
          font-size: 16px;
          color: #ff3926;
          font-weight: 700;
        }

        > span:nth-child(2) {
          font-size: 16px;
          color: #fff;
        }
      }
    }
  }

  .early-warning-data-title {
    width: 100%;
    height: 23px;
    padding: 0 35px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    > .early-warning-data-item {
      height: 100%;
      align-items: center;
    }
    > span {
      color: #00f6f5;
      font-size: 12px;
    }

    > img {
      width: 95%;
      height: 23px;
      position: absolute;
      left: 50%;
      top: 0;
      z-index: 99;
      transform: translateX(-50%);
    }
  }

  > .early-warning-data {
    width: 100%;
    flex: 1;
    overflow: auto;
    box-sizing: border-box;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    position: relative;

    > img {
      width: 100%;
      height: 100%;
      position: absolute;
      left: 0;
      top: 0;
    }
  }

  .early-warning-data-view {
    width: 100%;
    flex: 1;
    padding: 0 20px;
    box-sizing: border-box;
    z-index: 99;
    display: flex;
    flex-direction: column;

    .early-warning-data-wrap {
      width: 100%;
      flex: 1;
      overflow-x: hidden;
      overflow-y: auto;
      box-sizing: border-box;
    }
  }

  .early-warning-data-item {
    width: 100%;
    height: 30px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;

    > span {
      width: 100px;
      font-size: 17px;
      display: flex;
      justify-content: center;
      color: #fff;
      cursor: pointer;
    }

    > span:nth-child(1) {
      width: 50px;
    }

    > span:nth-child(2) {
      width: 100px;
    }

    > span:nth-child(3) {
      width: 80px;
    }

    > span:nth-child(4) {
      width: 178px;
    }

    > span:nth-child(5) {
      width: 100px;
    }
  }
}
</style>
